# from selenium import webdriver
from seleniumwire import webdriver  # 使用 seleniumwire 替代 webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By as By
from readExcel import *
from component import action
import time
import unittest
class run(unittest.TestCase):
    def setUp(self):
        int.read(self)
        # 配置 SeleniumWire
        options = webdriver.ChromeOptions()
        options.add_experimental_option('detach', True)
        self.driver = webdriver.Chrome(options=options)
        self.driver.implicitly_wait(5)
        # self.driver.maximize_window()
        self.driver.get(self.dfs[self.sheetName[0]].iloc[0, 0])

    def tearDown(self):
        self.driver.quit()  # 退出浏览器
        int.save(self)

    def test_login(self):
        rows, columns = self.dfs['login'].shape # 获取行列数
        data = self.dfs['login']
        self.tools(data, 'login', rows, columns)
    
    # def test_lightIndex(self):
    #     rows, columns = self.dfs['lightIndex'].shape # 获取行列数
    #     data = self.dfs['lightIndex']
    #     self.tools(data, rows, columns)
    
    def tools(self,data,list,rows,columns):
        for i in range(rows):
            type = None
            if list == 'login':
                if data.iloc[i, 2] == 'submit-btn':
                    time.sleep(5)            
            if data.iloc[i, 1] == 'id':
                type = By.ID
            elif data.iloc[i, 1] == 'class':
                type = By.CLASS_NAME
            elif data.iloc[i, 1] == 'css':
                type = By.CSS_SELECTOR
            elif data.iloc[i, 1] == 'path':
                type = By.XPATH

            if data.iloc[i,0] == 'input':
                action.input(self,data,type,i,columns)
            elif data.iloc[i,0] == 'click':
                action.click(self,data,type,i,columns)


if __name__ == '__main__':
    unittest.main()